import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    cartList:[]
  },
  getters: {
  },
  mutations: {
    addCart(state,obj){
       let bool = state.cartList.find(item=>item._id==obj._id)
       if(bool){
          bool.num++
       }else{
           state.cartList.push({
            ...obj,
            num:1,//新加的表示数量的字段
            status:false,//做全选，全不选的状态
           })
       }
      console.log(state.cartList);
    },
    // 全选
    changeAll(state,all){
        state.cartList.forEach(item=>item.status = all)
    },
    // 删除所选
    delSelect(state){
       state.cartList = state.cartList.filter(item=>!item.status)
    }
  },
  actions: {
  },
  modules: {
  }
})
